import { request } from '@umijs/max';
import { PageResponse } from './index';

// 轮播图状态枚举
export enum CarouselStatus {
  INACTIVE = 0,
  ACTIVE = 1,
}

// 轮播图详情接口
export interface CarouselInfo {
  id: number;
  title: string;
  imageId: string;
  linkUrl: string;
  description: string;
  sortOrder: number;
  status: CarouselStatus;
  createTime?: string;
  updateTime?: string;
}

// 轮播图添加请求
export interface CarouselAddRequest {
  title: string;
  imageId: string;
  linkUrl: string;
  description: string;
  sortOrder: number;
  status: CarouselStatus;
}

// 轮播图更新请求
export interface CarouselUpdateRequest extends CarouselAddRequest {
  id: number;
}

// 分页查询请求
export interface CarouselPageRequest {
  pageCurrent: number;
  pageSize: number;
  keyword?: string;
  status?: CarouselStatus;
}

// 前台轮播图项目接口
export interface CarouselItem {
  id: number;
  title: string;
  imageId: string;
  linkUrl: string;
  description: string;
  sortOrder: number;
}

// API 接口
export async function getCarouselPage(params: CarouselPageRequest) {
  return request<PageResponse<CarouselInfo>>('/carousel/back/page', {
    method: 'POST',
    data: params,
  });
}

export async function addCarousel(data: CarouselAddRequest) {
  return request('/carousel/back', {
    method: 'POST',
    data,
  });
}

export async function updateCarousel(data: CarouselUpdateRequest) {
  return request('/carousel/back', {
    method: 'PUT',
    data,
  });
}

export async function deleteCarousel(idList: number[]) {
  const ids = idList.join(',');
  return request(`/carousel/${ids}`, {
    method: 'DELETE',
  });
}

// 获取前台轮播图列表
export async function getCarouselList() {
  return request<CarouselItem[]>('/carousel/listAll', {
    method: 'GET',
  });
}
